package framework;

import java.util.Iterator;
import java.util.Vector;

/**
 * Sales is used to save completed orders
 */
public class Sales {
	private Vector<Order> orders = new Vector<Order>();
	private double totalSale = 0;
	
	/**
	 * Adding an order to Sales indicates that it has been completed
	 */
	public void addOrder(Order order) {
		orders.add(order);
	}
	
	/**
	 * Enter the order number to get the order
	 * @param orderCode the code of the order
	 * @return the Order object
	 */
	public Order getOrder(int orderCode) {
		Order target = null;
		for (Order o : orders) {
			if (o.getOrderCode() == orderCode) {
				target = o;
			} else {
				System.out.println("The order is not exist");
			}
		}
		return target;
	}
	
	/**
	 * Calculate the total price of all orders
	 */
	public double getTotalSale() {
		for (Order o : orders) {
			totalSale += o.getTotalCost();
		}
		return totalSale;
	}
	
	/**
	 * Get the number of Orders.
	 * @return the number of orders.
	 */
	public int getNumberOfOrders() {
		return orders.size();
	}
	
	/**
	 * Returns an iterator over the Orders in this Sales.
	 *
	 * return an {@link Iterator}
	 */
	public Iterator<Order> getSalesIterator() {
		return orders.iterator();
	}
	
	/**
	 * Display the information of Orders in the Sales
	 */
	public String toString() {
		String infoOfOrders = null; 
		for(Order o : orders) {
			infoOfOrders += o.toString();
		}
		return infoOfOrders;
	}
	
}
